(() => {
    /*
     *  反混淆 @一七年夏 2021年7月24日23:32:48 
     */

    function getAttribute(object, name, normal) {
        return object.getAttribute(name) || normal
    }

    function findAllElement(i) {
        return document.getElementsByTagName(i)
    }

    function attr() {
        let element = findAllElement("script");
        let _length = element.length;
        let lastElement = element[_length - 1];
        return {
            length: _length,
            zIndex: getAttribute(lastElement, "zIndex", -1),
            opacity: getAttribute(lastElement, "opacity", 0.5),
            color: getAttribute(lastElement, "color", "0,0,0"),
            count: getAttribute(lastElement, "count", 999)
        }
    }

    let canvasWidth;
    let canvasHeight;

    function initWidthAndHeight() {
        canvasWidth = canvas.width = window.innerWidth || document.documentElement.clientWidth || document.body
            .clientWidth;
        canvasHeight = canvas.height = window.innerHeight || document.documentElement.clientHeight || document
            .body.clientHeight;
    }

    let random = Math.random;
    function startAnime() {
        context.clearRect(0, 0, canvasWidth, canvasHeight);
        let pointList = [cursor].concat(newPoint);
        newPoint.forEach(function(iPoint) {
            iPoint.x += iPoint.xa;
            iPoint.y += iPoint.ya;
            iPoint.x = iPoint.x % canvasWidth;
            iPoint.y = iPoint.y % canvasHeight;
            iPoint.xa += (random() - 0.5) * 0.1;
            iPoint.xa *= 0.999;
            iPoint.ya += (random() - 0.5) * 0.1;
            iPoint.ya *= 0.999;
            context.fillRect(iPoint.x - 0.5, iPoint.y - 0.5, 1, 1);
            for (let j = 0; j < pointList.length; j++) {
                let jPoint = pointList[j];
                if (iPoint !== jPoint && jPoint.x !== null && jPoint.y !== null) {
                    let deltaX = iPoint.x - jPoint.x;
                    let deltaY = iPoint.y - jPoint.y;
                    let moduleXY = deltaX * deltaX + deltaY * deltaY;
                    // 下面这段代码，我也不知道写了什么，但是别碰，碰了就炸
                    moduleXY < jPoint.max && (
                        jPoint === cursor &&
                        moduleXY >= jPoint.max / 2 &&
                        (iPoint.x -= 0.03 * deltaX, iPoint.y -= 0.03 * deltaY));
                    //↑谁看懂，谁NB
                    let a = (jPoint.max - moduleXY) / jPoint.max;
                    if (a <= 0) continue;
                    //let addX = 0.1 / deltaX;
                    //let addY = 0.1 / deltaY;
                    //iPoint.xa += addX;
                    //iPoint.ya += addY;
                    //jPoint.xa -= addX;
                    //jPoint.ya -= addY;
                    context.beginPath();
                    context.lineWidth = a / 2;
                    context.strokeStyle = "rgba(" + nowAttr.color + "," + (a + 0.2) + ")";
                    context.moveTo(iPoint.x, iPoint.y);
                    context.lineTo(jPoint.x, jPoint.y);
                    context.stroke();
                }
            }
            pointList.splice(pointList.indexOf(iPoint), 1)
        });
        AnimationFrame(startAnime);
    }
    let canvas = document.createElement("canvas");
    let nowAttr = attr();
    let canvasID = "c_n" + nowAttr.length;
    let context = canvas.getContext("2d");
    let r;
    let n;
    let AnimationFrame =
        window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function(i) {
            window.setTimeout(i, 1000 / 45)
        };
    let cursor = {
        x: null,
        y: null,
        max: 20000
    };
    canvas.className = "particle_canvas";
    let browserName = navigator.userAgent.toLowerCase();
    if (/msie/i.test(browserName) && !/opera/.test(browserName)) {
        canvas.className += ' ie10_gte';
    };
    canvas.id = canvasID;
    canvas.style.cssText =
        "position:fixed; top:0; left:0; z-index:" + nowAttr.zIndex +
        "; opacity:" + nowAttr.opacity;
    findAllElement("body")[0].appendChild(canvas);
    initWidthAndHeight();
    window.onresize = initWidthAndHeight;
    window.onmousemove = function(e) {
        e = e || window.event;
        cursor.x = e.clientX;
        cursor.y = e.clientY;
    };
    window.onmouseout = function() {
        cursor.x = null;
        cursor.y = null
    };
    let newPoint;
    for (newPoint = [], p = 0; nowAttr.count > p; p++) {
        let h = random() * canvasWidth;
        let g = random() * canvasHeight;
        let q = 2 * random() - 1;
        let d = 2 * random() - 1;
        newPoint.push({
            x: h,
            y: g,
            xa: q,
            ya: d,
            max: 6000
        })
    }
    setTimeout(function() {
        startAnime()
    }, 250)
})();
